﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KLS.PPDS.Core.Entity;
using System.IO;
using KLS.PPDS.Utility;
using KLS.PPDS.Utilities;
using KLS.PPDS.Utilities.Attributes;
using KLS.PPDS.ApplicationService.Manager;
using KLS.PPDS.Utilities.Entity;
using KLS.PPDS.Resources;
using KLS.PPDS.Utility.Extension;
using System.Runtime.CompilerServices;

namespace KLS.PPDS.Web.Models
{
    public class ArticleContentModel
    {


        public static string SaveCommnetsText(string comments, int pubId, int artId, int contntId)
        {
            var reslt = string.Empty;
            var pub = PublicationManager.GetPublicationById(pubId);
            if (!String.IsNullOrEmpty(comments))
            {
                reslt = FileUtil.WriteTextFile(comments, ArticleContentModel.GetArtileContentBaseFolder(pub.CompanyId, pubId, artId, contntId), "Commnets.txt", false);
            }

            return reslt;
        }

        public static ArticleContentViewModel GetViewModel(int id, int publicationId) 
        {

            var model = new ArticleContentViewModel();
            
            var content = ArticleContentManager.GetArticleContentById(id);
            var pub = PublicationManager.GetPublicationById(publicationId);

            content.CopyPropertyValue<ArticleContent, ArticleContentViewModel>(model);
            model.Images = ContentImageManager.GetContentImageByContentId(content.Id);
            model.CompanyId = pub.CompanyId;
            model.PublicationId = publicationId;
            //model.ImageFiles = FileUtil.NewGetImageFiles((model.ImageFilePath));
            model.TextFiles = FileUtil.NewGetTextFiles((model.TextFilePath));
            model.Article = ArticleManager.GetArticleById(model.ArticleId);

            return model;
        }

        public static ArticleContentViewModel GetViewModel(int id)
        {

            var model = new ArticleContentViewModel();

            var content = ArticleContentManager.GetArticleContentById(id);
            var art = ArticleManager.GetArticleById(content.ArticleId);
            var pub = PublicationManager.GetPublicationById(art.PublicationId);

            content.CopyPropertyValue<ArticleContent, ArticleContentViewModel>(model);
            model.Images = ContentImageManager.GetContentImageByContentId(content.Id);
            model.CompanyId = pub.CompanyId;
            model.PublicationId = pub.Id;
            //model.ImageFiles = FileUtil.NewGetImageFiles((model.ImageFilePath));
            model.TextFiles = FileUtil.NewGetTextFiles((model.TextFilePath));
            model.Article = ArticleManager.GetArticleById(model.ArticleId);

            return model;
        }


        public static string DeleteImageFile(string file) 
        {
            FileUtil.DeleteImageFile(file);
            return string.Empty;
        }

        public static string DeleteTextFolder(string path)
        {
            FileUtil.DeleteFolder(path);
            return string.Empty;
        }

        public static string Delete(int publicationId, int articleId, int id) 
        {
            var content = ArticleContentManager.GetArticleContentById(id);
            var pub = PublicationManager.GetPublicationById(publicationId);
            if (content != null && content.Id > 0) 
            {
                ArticleContentManager.Delete(content);
                FileUtil.DeleteFolder(GetArtileContentBaseFolder(pub.CompanyId, publicationId, articleId, id));
            }
            return string.Empty;
        }


        public static string SaveNewFileDb(int id, string fileName, string diskFileName,int index , double size) 
        {
            return SaveFileDb(id, diskFileName, diskFileName, fileName, index, size, false, false);
        }

        public static string SaveFileDbCutoutRetouch(int id, string oldDiskFileName, string newDiskFileName, bool cutout, bool retouch) 
        {
            var result = string.Empty;

            var x = ContentImageManager.GetContentImageByIdAndDiskFileName(id, oldDiskFileName);

            if (x == null || (x != null && x.Id < 1))
            {
                x = new ContentImage();
            }

            x.DiskFileName = newDiskFileName;
            x.Cutout = cutout;
            x.ContentId = id;
            //x.Name = fileName;
            x.Retouch = retouch;
           // x.Size = (int)size;
            ContentImageManager.Save(x);


            return result;   
        }

        public static string SaveFileDb( int Id, string oldDiskFileName,string newDiskFileName,  string fileName,int index, double size, bool cutout, bool retouch) 
        {
            var result = string.Empty;

            var x = ContentImageManager.GetContentImageByIdAndDiskFileName(Id, oldDiskFileName);

            if (x == null || (x != null && x.Id < 1)) 
            {
                x = new ContentImage();
            }

            x.DiskFileName = newDiskFileName;
            x.Cutout = cutout;
            x.ContentId = Id;
            x.Name = fileName;
            x.Retouch = retouch;
            x.Size = (int)size;
            x.ImageIndex = index;
            ContentImageManager.Save(x);


            return result;   
        }

        public static string DeleteFileDb(int id, string diskFileName) 
        {
            var result = string.Empty;

            ContentImageManager.Delete(id, diskFileName);

            return result;
        }

        /// <summary>
        /// ValidateUploadFile
        /// </summary>
        /// <param name="contentId"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public static bool  ValidateUploadFile(int contentId, string option) 
        {
            var model = GetViewModel(contentId);
            if (option.Contains("img") && model.IsGraphicsDisable) 
            {
                return false;
            }

            if (option.Contains("txt") && model.IsTextDisable)
            {
                return false;
            }

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <param name="imagePath"></param>
        /// <param name="thumbFilePath"></param>
        /// <param name="textPath"></param>
        /// <param name="option"></param>
        /// <param name="artId"></param>
        /// <param name="Id"></param>
        /// <returns></returns>
        /// 
        [MethodImpl(MethodImplOptions.Synchronized)]
        public static string SaveFiles(HttpPostedFileBase file, string imagePath, string thumbFilePath, string textPath, string option, int artId, int Id) 
        {
           // ConvertBytesToMegabytes

            //var cont = ArticleContentManager.GetArticleContentById(Id);


           





            var size = ConvertBytesToMegabytes(file.ContentLength);
            var ofileName = Path.GetFileName(file.FileName);
            if (WebConfig.MaxUploadFileSizeMB < size) 
            {
                return "('" + ofileName + "')" + string.Format(CommonMessage.MaximumUploadFileSize + CommonString.Megabyte, WebConfig.MaxUploadFileSizeMB);
            }

            var extension = Path.GetExtension(file.FileName);
          

            if (String.IsNullOrEmpty(extension)) 
            {
                return "('"+ ofileName +"')" + "File type not supported";
            }

            var result = string.Empty;
            var fileName = string.Empty;
            var sFileName = string.Empty;
            //if image files
            if (UploadFileTypeManager.IsValidImageFile(ofileName) && option.Contains("img")) 
            {               
                var count = FileUtil.GetImageFiles(imagePath).Count + 1;

                fileName = FileUtil.GetDiskImageFileName(count.ToString(), ofileName).ReplaceSpecialCharecterFileName();
                var thumb = FileUtil.ImageGetThumbnailsFileName(fileName);

                FileUtil.SaveThumbnails(file.InputStream, thumbFilePath, thumb);

                file.SaveAs(Path.Combine(imagePath, fileName));

                SaveNewFileDb(Id, ofileName, fileName, count, size);


                //result = true;
            }
            else if (UploadFileTypeManager.IsValidTextFile(ofileName) && option.Contains("txt"))
            {
                var count = FileUtil.GetTextFiles(textPath).Count + 1;
                fileName = FileUtil.GetDiskTextFileName(count.ToString(), ofileName).ReplaceSpecialCharecterFileName();

                file.SaveAs(Path.Combine(textPath, fileName));
                //result = true;
            }
            else 
            {
                result = "('" + ofileName + "')" + "File type not supported";
            }

            return result;
        }

        static double ConvertBytesToMegabytes(long bytes)
        {
            return (bytes / 1024f) / 1024f;
        }

        //public static void ProcessImageFiles(List<string> checkedFileNames, string imagePath, int artId, int Id) 
        //{
        //    var imageFiles = FileUtil.GetImageFiles(imagePath);
            
        //    var filePrefix = string.Empty;
        //    var filename = string.Empty;
        //    var cutout = false;
        //    var retouch = false;

            
        //    if (imageFiles != null && imageFiles.Count > 0 ) 
        //    {
        //        if (checkedFileNames != null && checkedFileNames.Count > 0)
        //        {
        //            //these are (retouch/cutout) chkbox inputs
        //            foreach (var item in checkedFileNames)
        //            {
        //                var temp = FileUtil.GetDiskImageOnlyFileName(item);

        //                var matched = checkedFileNames.Where(c => c.Contains(temp)).OrderBy(c => c).ToList();

        //                if (matched != null && matched.Count > 0)
        //                {
        //                    if (matched.Count == 2)
        //                    {
        //                        filePrefix = CommonConstant.Cutout + "_" + CommonConstant.Retouch + "_";
        //                    }

        //                    else if (matched.Count == 1)
        //                    {
        //                        if (matched[0].Contains(CommonConstant.Cutout))
        //                        {
        //                            filePrefix = CommonConstant.Cutout + "_";
        //                        }
        //                        else if (matched[0].Contains(CommonConstant.Retouch))
        //                        {
        //                            filePrefix = CommonConstant.Retouch + "_";
        //                        }
        //                    }
        //                }

        //                //constructing file names
        //                filename = filePrefix + temp;
        //                var oldFile = imageFiles.Where(c => c.Contains(temp)).FirstOrDefault();

        //                //rename changes
        //                if (!File.Exists(Path.Combine(imagePath,filename)) && !String.IsNullOrEmpty(oldFile) && oldFile.Equals(filename).Equals(false))
        //                {
        //                    FileUtil.RenameFile(imagePath, oldFile, filename);
        //                    cutout = false;
        //                    retouch = false;

        //                    if (filename.Contains(CommonConstant.Cutout + "_")) 
        //                    {
        //                        cutout = true;
        //                    }
        //                    if (filename.Contains(CommonConstant.Retouch + "_"))
        //                    {
        //                        retouch = true;
        //                    }
        //                    //update to db
        //                    SaveFileDbCutoutRetouch(Id, oldFile, filename, cutout, retouch);

        //                }
        //            }

        //            //reload files
        //            imageFiles = FileUtil.GetImageFiles(imagePath);

        //            var retouchCutout = imageFiles.Where(c => c.Contains(CommonConstant.Retouch) || c.Contains(CommonConstant.Cutout)).ToList();

        //            //Indivisual clearing cutout/retouch file name
        //            foreach (var item in retouchCutout) 
        //            {
        //                var temp = FileUtil.GetDiskImageOnlyFileName(item);

        //                var found = checkedFileNames.Where(c => c.Contains(temp)).FirstOrDefault();

        //                if (String.IsNullOrEmpty(found)) 
        //                {
        //                    FileUtil.RenameFile(imagePath, item, temp);
        //                    cutout = false;
        //                    retouch = false;

        //                    if (temp.Contains(CommonConstant.Cutout + "_"))
        //                    {
        //                        cutout = true;
        //                    }
        //                    if (temp.Contains(CommonConstant.Retouch + "_"))
        //                    {
        //                        retouch = true;
        //                    }
        //                    //update to db
        //                    SaveFileDbCutoutRetouch(Id, item, temp, cutout, retouch);
        //                }
        //            }                    
        //        }
        //        //clearing file name to original
        //        else if (checkedFileNames == null || (checkedFileNames != null && checkedFileNames.Count == 0)) 
        //        {
        //            foreach (var file in imageFiles) 
        //            {
        //                if (file.Contains(CommonConstant.Retouch) || file.Contains(CommonConstant.Cutout)) 
        //                {
        //                    var temp = FileUtil.GetClearFileName(file);
        //                    FileUtil.RenameFile(imagePath, file, temp);
        //                    cutout = false;
        //                    retouch = false;

        //                    //update to db
        //                    SaveFileDbCutoutRetouch(Id, file, temp, cutout, retouch);
        //                }
        //            }
        //        }
        //    }
        //}

        public static void NewProcessImageFiles(List<string> checkedFileNames, string imagePath, int artId, int Id)
        {
            //var imageFiles = FileUtil.GetImageFiles(imagePath);
            var imageFiles = ContentImageManager.GetContentImageByContentId(Id);
            //var imageFiles = (from items in ContentImageManager.GetContentImageById(Id) 
            //                      select items.names
            //                      );



            if (imageFiles != null && imageFiles.Count > 0 && checkedFileNames != null )
            {
                foreach (var item in imageFiles)
                {
                    var matched = checkedFileNames.Where(c => c.Contains(item.CompareFileName)).ToList();
                    if (matched != null )
                    {
                        if (matched.Count == 2)
                        {
                            item.Cutout = true;
                            item.Retouch = true;
                        }
                        else if (matched.Count == 1)
                        {
                            item.Cutout = false;
                            item.Retouch = false;

                            if (matched[0].Contains(CommonConstant.Cutout))
                            {
                                item.Cutout = true;

                            }
                            if (matched[0].Contains(CommonConstant.Retouch))
                            {
                                item.Retouch = true;
                            }

                        }
                        else
                        {
                            item.Cutout = false;
                            item.Retouch = false;
                        }
                        ContentImageManager.Save(item);
                    }

                }
            }
            //else if (imageFiles != null && imageFiles.Count > 0 && (checkedFileNames == null || (checkedFileNames != null && checkedFileNames.Count == 0)))
            //{ 
            //}
            
        }

        public static string SaveArticleContent(ArticleContentViewModel model)
        {

            var content = new ArticleContent();

            model.CopyPropertyValue<ArticleContentViewModel,ArticleContent >(content);


            ArticleContentManager.Save(content);
            var result = string.Empty;

            return result;
        }

        public static string GetCompanyBaseFolder(int comId)
        {
            return Path.Combine(WebConfig.BaseFolder, string.Format("company_{0}", comId));
        }
        public static string GetPulicationBaseFolder(int comId, int pubId)
        {
            return Path.Combine(GetCompanyBaseFolder(comId), string.Format("publication_{0}", pubId));
            //return Path.Combine(WebConfig.BaseFolder, string.Format(@"company_{0}\publication_{1}\", comId, pubId));
        }

        public static string GetArtileBaseFolde(int comId, int pubId, int artId)
        {
            return Path.Combine(GetPulicationBaseFolder(comId, pubId), string.Format("article_{0}", artId));
            //return Path.Combine(WebConfig.BaseFolder, string.Format(@"company_{0}\publication_{1}\article_{2}\", comId, pubId, artId));
        }

        public static string GetArtileContentBaseFolder(int comId, int pubId, int artId, int id)
        {
            return Path.Combine(GetArtileBaseFolde(comId, pubId, artId), string.Format("content_sub_{0}", id));
            //return Path.Combine(WebConfig.BaseFolder, string.Format(@"company_{0}\publication_{1}\article_{2}\content_sub_{3}\", comId, pubId, artId, id));         
        }
                

        public static string GetArtileContentImageFolder(int comId, int pubId, int artId, int id)
        {
            return Path.Combine(GetArtileContentBaseFolder(comId, pubId, artId, id), "Images");
            //return Path.Combine(WebConfig.BaseFolder, string.Format(@"company_{0}\publication_{1}\article_{2}\content_sub_{3}\Images\", comId, pubId, artId, id)); 
        }       

        public static string GetArtileContentImageThumbnailFolder(int comId, int pubId, int artId, int id)
        {
            return Path.Combine(GetArtileContentImageFolder(comId, pubId, artId, id), "thumbs");
            //return Path.Combine(WebConfig.BaseFolder, string.Format(@"company_{0}\publication_{1}\article_{2}\content_sub_{3}\Images\thumbs\", comId, pubId, artId, id)); 
        }        

        public static string GetArtileContentTextFolder(int comId, int pubId, int artId, int id)
        {
            return Path.Combine(GetArtileContentBaseFolder(comId, pubId, artId, id), "Attachment");
            //return Path.Combine(WebConfig.BaseFolder, string.Format(@"company_{0}\publication_{1}\article_{2}\content_sub_{3}\Attachment\", comId, pubId, artId, id));
        }             

        

        public static string GetPackageCompanyBaseFolder(Company company)
        {
            return Path.Combine(WebConfig.PublicationPackageFolder, string.Format("company_{0}_{1}", company.Id, company.CompanyName.ReplaceSpecialCharecter()));
        }       

        public static string GetPackageCompanyBaseFolder(int companyId)
        {
            return GetPackageCompanyBaseFolder(CompanyManager.GetCompany(companyId));
        }

        public static string GetPackagePublicationBaseFolder(Publication publication)
        {
            return Path.Combine(GetPackageCompanyBaseFolder(publication.Company), string.Format("publication_{0}_{1}", publication.Id, publication.PublicationName.ReplaceSpecialCharecter()));
        }

        public static string GetPackagePublicationBaseFolder(int publicationId)
        {
            return GetPackagePublicationBaseFolder(PublicationManager.GetPublicationById(publicationId));
        }

        public static string GetPublicationPackageArtileBaseFolde(Article article)
        {
            string artileFolder = string.Empty;
            if (string.IsNullOrWhiteSpace(article.Headline))
                artileFolder = Path.Combine(GetPackagePublicationBaseFolder(PublicationManager.GetPublicationById(article.PublicationId)), string.Format("article_{0}", article.Id));
            else
                artileFolder = Path.Combine(GetPackagePublicationBaseFolder(PublicationManager.GetPublicationById(article.PublicationId)), string.Format("article_{0}_{1}", article.Id, article.Headline.ReplaceSpecialCharecter()));
            return artileFolder;           
        }

        public static string GetPublicationPackageArtileBaseFolde(int articleId)
        {
            return GetPublicationPackageArtileBaseFolde(ArticleManager.GetArticleById(articleId));
        }

        public static string GetPackageArtileContentBaseFolder(ArticleContent content)
        {
            string artileContentFolder = string.Empty;
            if (string.IsNullOrWhiteSpace(content.Headline))
                artileContentFolder = Path.Combine(GetPublicationPackageArtileBaseFolde(ArticleManager.GetArticleById(content.ArticleId)), string.Format("content_sub_{0}", content.Id));
            else
                artileContentFolder = Path.Combine(GetPublicationPackageArtileBaseFolde(ArticleManager.GetArticleById(content.ArticleId)), string.Format("content_sub_{0}_{1}", content.Id, content.Headline.ReplaceSpecialCharecter()));
            return artileContentFolder;
        }

        public static string GetPackageArtileContentBaseFolder(int contentId)
        {
            return GetPackageArtileContentBaseFolder(ArticleContentManager.GetArticleContentById(contentId));
        }


        public static string GetPackageArtileContentTextFolder(ArticleContent content)
        {
            return Path.Combine(GetPackageArtileContentBaseFolder(content), "Attachment");            
        }

        public static string GetPackageArtileContentTextFolder(int contentId)
        {
            return Path.Combine(GetPackageArtileContentBaseFolder(contentId), "Attachment");
        }

        public static string GetPackageArtileContentImageFolder(ArticleContent content)
        {
            return Path.Combine(GetPackageArtileContentBaseFolder(content), "Images");
        }

        public static string GetPackageArtileContentImageFolder(int contentId)
        {
            return Path.Combine(GetPackageArtileContentBaseFolder(contentId), "Images");
        }

        public static string GetPackageArtileContentImageThumbnailFolder(ArticleContent content)
        {
            return Path.Combine(GetPackageArtileContentImageFolder(content), "thumbs");
        }

        public static string GetPackageArtileContentImageThumbnailFolder(int contentId)
        {
            return Path.Combine(GetPackageArtileContentImageFolder(contentId), "thumbs");
        }

        public static string GetPublicationLayoutFolder(Publication publication)
        {
            return Path.Combine(GetPackagePublicationBaseFolder(publication), "Indesign");            
        }
        public static string GetPublicationLayoutFolder(int publicationId)
        {
            return Path.Combine(GetPackagePublicationBaseFolder(publicationId), "Indesign");
        }
    }

    public class ArticleContentViewModel : ArticleContent
    {
        public int PublicationId { get; set; }
        public int CompanyId { get; set; }
        public string TextFileError { get; set; }
        public string ImageFileError { get; set; }
        public List<ArticleFile> ImageFiles { get; set; }
        public List<ArticleFile> TextFiles { get; set; }
        public Article Article { get; set; }

        public string OldComments { get; set; }
        public string OldHeadline { get; set; }
       
        /// <summary>
        /// OldTextDisable
        /// </summary>
        public bool OldTextDisable { get; set; }
        /// <summary>
        /// OldReadyForEditing
        /// </summary>
        public bool OldReadyForEditing { get; set; }

        /// <summary>
        /// OldReadyForGraphics
        /// </summary>
        public bool OldReadyForGraphics { get; set; }

        /// <summary>
        /// SupportedTexFilesExt
        /// </summary>
        public string SupportedTextFilesExt 
        {
            get 
            {
                return UploadFileTypeManager.GetSupportedTextFileExtForUploadify();
            }
        }
        /// <summary>
        /// SupportedImageFilesExt
        /// </summary>
        public string SupportedImageFilesExt
        {
            get
            {
                return UploadFileTypeManager.GetSupportedImageFileExtForUploadify();
            }
        }

        /// <summary>
        /// IsGraphicsDisable
        /// </summary>
        public bool IsGraphicsDisable
        {
            get
            {
                try
                {
                    if (this.Article != null)
                    {
                        if (this.Article.IsReadyForGraphic.Equals(true) || CommonSession.IsUserGraphicsDesigner )
                        {
                            return true;
                        }
                    }
                }
                catch (Exception )
                {
                    
                    
                }
                return false;
            }
        }

        /// <summary>
        /// IsTextDisable
        /// </summary>
        public bool IsTextDisable
        {
            get
            {
                try
                {
                    if (this.Article != null)
                    {
                        if (this.Article.IsReadyForEditor.Equals(true) && !(CommonSession.IsUserSuperAdmin || CommonSession.IsUserEditor))
                        {
                            return true;
                        }
                        else if (CommonSession.IsUserGraphicsDesigner)
                        {
                            return true;
                        }
                        else if (this.Article.IsReadyForGraphic.Equals(true))
                        {
                            return true;
                        }
                    }
                }
                catch (Exception )
                {
                    
                    
                }
                return false;
            }
        }

        /// <summary>
        /// IsDeleteButtonDisable
        /// </summary>
        public bool IsDeleteButtonDisable 
        {
            get 
            {
                try
                {
                    if (this.IsTextDisable || (this.CreatedBy.HasValue && this.CreatedBy.Value.Equals(CommonSession.UserId).Equals(false) && CommonSession.IsUserJournalist && this.IsReadyForEditor.Equals(false)))
                    {

                        return true;
                    }
                }
                catch (Exception )
                {
                    
                   
                }

                return false;
            }
        }

        /// <summary>
        /// IsGraphicsChkDisable
        /// </summary>
        public bool IsGraphicsChkDisable
        {
            get
            {
                try
                {
                    if (this.IsTextDisable || CommonSession.IsUserJournalist)
                    {
                       
                            return true;
                       
                    }
                }
                catch (Exception )
                {
                    
                    //throw;
                }
                return false;
            }
        }

        /// <summary>
        /// IsTextChkDisable
        /// </summary>
        public bool IsTextChkDisable
        {
            get
            {
                try
                {
                    if (this.Article != null)
                    {
                        if (this.Article.IsReadyForGraphic.Equals(true) || this.Article.IsReadyForEditor.Equals(true) && !(CommonSession.IsUserSuperAdmin || CommonSession.IsUserEditor))
                        {
                            return true;
                        }
                    }
                }
                catch (Exception )
                {
                    
                    //throw;
                }
                return false;
            }
        }

        /// <summary>
        /// ThumbsFilePath
        /// </summary>
        public string ThumbsFilePath 
        {
            get 
            {

                var paths = ArticleContentModel.GetArtileContentImageThumbnailFolder(this.CompanyId,this.PublicationId, this.ArticleId, this.Id);
                
                if (this.Article != null && this.Article.IsReadyForGraphic) 
                {
                    //paths = paths.Replace(WebConfig.BaseFolder, WebConfig.PublicationPackageFolder);
                   //paths= ArticleContentModel.GetPackageArtileContentImageThumbnailFolder(this.CompanyId, this.PublicationId, this.ArticleId,this.Article.Headline, this.Id,this.Headline);
                    paths = ArticleContentModel.GetPackageArtileContentImageThumbnailFolder(this.Id);
                }


                return paths;
                //return Path.Combine(WebConfig.BaseFolder, string.Format(@"{0}\articles\article_{1}\content_sub_{2}\Images\thumbs", this.PublicationId, this.ArticleId, this.Id));
            }
        }

        /// <summary>
        /// ImageFilePath
        /// </summary>
        public string ImageFilePath 
        {
            get 
            {
                var paths = ArticleContentModel.GetArtileContentImageFolder(this.CompanyId,this.PublicationId, this.ArticleId, this.Id);
                if (this.Article != null && this.Article.IsReadyForGraphic)
                {
                    //paths = paths.Replace(WebConfig.BaseFolder, WebConfig.PublicationPackageFolder);                    
                    //paths = ArticleContentModel.GetPackageArtileContentImageFolder(this.CompanyId, this.PublicationId, this.ArticleId, this.Article.Headline, this.Id, this.Headline);
                    paths = ArticleContentModel.GetPackageArtileContentImageFolder(this.Id);
                }
                return paths;
                //return Path.Combine(WebConfig.BaseFolder, string.Format(@"{0}\articles\article_{1}\content_sub_{2}\Images",this.PublicationId, this.ArticleId, this.Id));
            }
        }

        /// <summary>
        /// TextFilePath
        /// </summary>
        public string TextFilePath 
        {
            get 
            {
                var paths = ArticleContentModel.GetArtileContentTextFolder(this.CompanyId, this.PublicationId, this.ArticleId, this.Id);
               
                if (this.Article != null && this.Article.IsReadyForGraphic)
                {
                    //paths = paths.Replace(WebConfig.BaseFolder, WebConfig.PublicationPackageFolder);
                    //paths = ArticleContentModel.GetPackageArtileContentTextFolder(this.CompanyId, this.PublicationId, this.ArticleId, this.Article.Headline, this.Id, this.Headline);
                    paths = ArticleContentModel.GetPackageArtileContentTextFolder(this.Id);
                }
                return paths;
                //return Path.Combine(WebConfig.BaseFolder, string.Format(@"{0}\articles\article_{1}\content_sub_{2}\Attachment", this.PublicationId, this.ArticleId, this.Id));                
            }
        }
    }
}